package org.zfes.snowier.zbss.xzy.router.solution;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.zbss.xzy.biz.solution.model.AlgorithmConfigItem;
import org.zfes.snowier.zbss.xzy.biz.solution.model.SolutionDeviceConfigValue;
import org.zfes.snowier.zbss.xzy.biz.solution.service.IAlgorithmConfigItemService;
import org.zfes.snowier.zbss.xzy.biz.solution.service.ISolutionDeviceConfigValueService;
import org.zfes.snowier.zbss.xzy.solution.ConfigValueUpdateDto;
import org.zfes.snowier.zbss.xzy.solution.SolutionDeviceConfigValueDto;
import org.zfes.snowier.core.data.SelectVo;
@Controller 
@RequestMapping("/manager/solution/config")
public class SolutionDeviceConfigValueController implements BaseController {

	
	@Autowired
	private ISolutionDeviceConfigValueService algorithmConfigItemValueService;
	
	@Autowired
	private IAlgorithmConfigItemService algorithmConfigItemService;
	
	
	  @RequestMapping(value="/loadConfigValueTreeGrid", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	  public @ResponseBody  Object loadConfigValueTreeGrid(Long deviceId,Long solutionId,Long algorithmId){
		  List<SolutionDeviceConfigValueDto>  treeGrid=  algorithmConfigItemValueService.loadDeviceConfigedValue(deviceId,solutionId,algorithmId);
		  return ajaxQuery("treeGrid", treeGrid);
	  }
	  
	  
	  @RequestMapping(value="/loadConfigValue", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	  public @ResponseBody  Object loadConfigValue(Long deviceId,Long solutionId,Long algorithmId,Long itemId){
		  Optional<SolutionDeviceConfigValue>  configValue =  algorithmConfigItemValueService.loadConfigValue(deviceId,solutionId,algorithmId,itemId);
		  Optional<AlgorithmConfigItem> configItem= algorithmConfigItemService.loadAlgorithmConfigItemById(itemId);
		  return ajaxQuery("configValue", configValue).put("configItem", configItem.get());
	  }
	  
	  @RequestMapping(value="/updateConfigValue", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	   public  @ResponseBody  Object  updateConfigValue(@RequestBody ConfigValueUpdateDto configValueUpdate) {
		  algorithmConfigItemValueService.updateConfigValue(configValueUpdate);
	      return ajaxDoneSuccess("操作成功 ");
	  }
	  
	  
    @RequestMapping(value="/loadAlgorithmConfigItemValueDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAlgorithmConfigItemValueDataSet(@RequestBody Map<String,Object> params){
	    DataSet dataSet=  algorithmConfigItemValueService.loadAlgorithmConfigItemValueDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
	
    @RequestMapping(value="/loadAlgorithmConfigItemValue/{id}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadAlgorithmConfigItemValue(@PathVariable("id")Long id){
		Optional<SolutionDeviceConfigValue> ops = algorithmConfigItemValueService.loadAlgorithmConfigItemValueById(id);
		return ajaxQuery("algorithmConfigItemValue",ops);
    }
	
	
    @RequestMapping(value="/deleteAlgorithmConfigItemValue/{id}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object deleteAlgorithmConfigItemValue(@PathVariable("id")Long id){
		algorithmConfigItemValueService.deleteAlgorithmConfigItemValue(id);
		return ajaxDoneSuccess("数据操作成功 ");
    }


    
}